package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.RoadmapCmStatus;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface RoadmapCmStatusDao {

    /**
     * 根据工厂+年份+版本查询cm认证状态
     *
     * @param pcbaCompanyId
     * @param versionY
     * @param versionN
     * @return
     */
    @Results(id = "roadmapCmStatusResultMap", value = {
            @Result(column = "roadmap_cm_status_id", property = "roadmapCmStatusId", jdbcType = JdbcType.INTEGER),
            @Result(column = "year", property = "year", jdbcType = JdbcType.INTEGER),
            @Result(column = "version_y", property = "versionY", jdbcType = JdbcType.INTEGER),
            @Result(column = "version_n", property = "versionN", jdbcType = JdbcType.VARCHAR),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "notes", property = "notes", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "pcba_company_id", property = "pcbaCompanyId", jdbcType = JdbcType.INTEGER),
            @Result(column = "submitter", property = "submitter", jdbcType = JdbcType.INTEGER),
            @Result(column = "auditors", property = "auditors", jdbcType = JdbcType.VARCHAR),
    })
    @Select("select * from " + DB1TableName.ROADMAP_CM_STATUS + " where pcba_company_id = #{pcbaCompanyId} and version_y = #{versionY} and version_n = #{versionN}")
    RoadmapCmStatus getRoadmapCmStatusByCompanyAndVersion(@Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("versionY") Integer versionY, @Param("versionN") String versionN);

    /**
     * 根据id查询
     *
     * @param roadmapCmStatusId
     * @return
     */
    @ResultMap(value = "roadmapCmStatusResultMap")
    @Select("select * from " + DB1TableName.ROADMAP_CM_STATUS + " where roadmap_cm_status_id = #{roadmapCmStatusId}")
    RoadmapCmStatus getRoadmapCmStatusById(@Param("roadmapCmStatusId") Integer roadmapCmStatusId);

    /**
     * 新增
     *
     * @param roadmapCmStatus
     * @return
     */
    @Insert("insert into " + DB1TableName.ROADMAP_CM_STATUS + " (year,version_y,version_n,status,notes,pcba_company_id,create_time,submitter,auditors) values " +
            "(#{roadmapCmStatus.year},#{roadmapCmStatus.versionY},#{roadmapCmStatus.versionN},#{roadmapCmStatus.status},#{roadmapCmStatus.notes},#{roadmapCmStatus.pcbaCompanyId},#{roadmapCmStatus.createTime},#{roadmapCmStatus.submitter},#{roadmapCmStatus.auditors})")
    Integer addRoadmapCmStatus(@Param("roadmapCmStatus") RoadmapCmStatus roadmapCmStatus);

    /**
     * 更新
     *
     * @param roadmapCmStatus
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.ROADMAP_CM_STATUS +
            "<set>" +
            "<if test='roadmapCmStatus.year != null and roadmapCmStatus.year != \"\" '>" +
            " year = #{roadmapCmStatus.year}," +
            "</if>" +
            "<if test='roadmapCmStatus.versionY != null and roadmapCmStatus.versionY != \"\" '>" +
            " version_y = #{roadmapCmStatus.versionY}," +
            "</if>" +
            "<if test='roadmapCmStatus.versionN != null  and roadmapCmStatus.versionN != \"\" '>" +
            " version_n = #{roadmapCmStatus.versionN}," +
            "</if>" +
            "<if test='roadmapCmStatus.status != null and roadmapCmStatus.status != \"\" '>" +
            " status = #{roadmapCmStatus.status}," +
            "</if>" +
            "<if test='roadmapCmStatus.notes != null '>" +
            " notes = #{roadmapCmStatus.notes}," +
            "</if>" +
            "<if test='roadmapCmStatus.pcbaCompanyId != null and roadmapCmStatus.pcbaCompanyId != \"\" '>" +
            " pcba_company_id = #{roadmapCmStatus.pcbaCompanyId}," +
            "</if>" +
            "<if test='roadmapCmStatus.updateTime != null '>" +
            " update_time = #{roadmapCmStatus.updateTime}," +
            "</if>" +
            "<if test='roadmapCmStatus.submitter != null and roadmapCmStatus.submitter != \"\" '>" +
            " submitter = #{roadmapCmStatus.submitter}," +
            "</if>" +
            "<if test='roadmapCmStatus.auditors != null and roadmapCmStatus.auditors != \"\" '>" +
            " auditors = #{roadmapCmStatus.auditors}," +
            "</if>" +
            "</set>" +
            " where roadmap_cm_status_id = #{roadmapCmStatus.roadmapCmStatusId}" +
            "</script>")
    Integer updateRoadmapCmStatus(@Param("roadmapCmStatus") RoadmapCmStatus roadmapCmStatus);
}
